//
//  GuideViewController.m
//  A_Project_DLS151129_SQ
//
//  Created by 151129-49宋强 on 16/1/29.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "GuideViewController.h"
#import "AppDelegate.h"
#import "HomeViewController.h"

@interface GuideViewController ()<UIScrollViewDelegate>
@property (nonatomic, retain)UIScrollView *scrollView;
@property (nonatomic, retain)UIScrollView *smallScrollView;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds)*3, CGRectGetHeight(self.view.bounds));
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    [_scrollView release];
    for (int i=0; i<3; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)*i, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
        [_scrollView addSubview:imageView];
        [imageView release];
    }
    
    UIImageView *smallImageView = [[UIImageView alloc] initWithFrame:CGRectMake(80, CGRectGetHeight(self.view.bounds)/4, CGRectGetWidth(self.view.bounds)/2, CGRectGetHeight(self.view.bounds)/2)];
    smallImageView.userInteractionEnabled = YES;
    smallImageView.backgroundColor = [UIColor redColor];
    [self.view addSubview:smallImageView];
    [smallImageView release];
    self.smallScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(smallImageView.bounds), CGRectGetHeight(smallImageView.bounds))];
    self.smallScrollView.scrollEnabled = NO;
    self.smallScrollView.delegate = self;
    self.smallScrollView.contentSize = CGSizeMake(CGRectGetWidth(smallImageView.bounds)*3, CGRectGetHeight(smallImageView.bounds));
    self.smallScrollView.pagingEnabled = YES;
    self.smallScrollView.bounces = NO;
    [_smallScrollView release];
    for (int i=0; i<3; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(smallImageView.bounds)*i, 0, CGRectGetWidth(smallImageView.bounds), CGRectGetHeight(smallImageView.bounds))];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
        [_smallScrollView addSubview:imageView];
        [imageView release];
    }
    [smallImageView addSubview:self.smallScrollView];
    [self.view addSubview:_scrollView];
    [self.view bringSubviewToFront:smallImageView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(Width * 2 + 50, HEIGHT - 40, Width - 100, 30);
    [btn setTitle:@"进入App" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:btn];
}
- (void)btn
{
    [UIView animateWithDuration:1.5 animations:^{
        self.scrollView.alpha = 0;
        self.smallScrollView.alpha = 0;
    } completion:^(BOOL finished) {
        [_scrollView removeFromSuperview];
        [_smallScrollView removeFromSuperview];
        AppDelegate *app = [[UIApplication sharedApplication] delegate];
        //第一次进入更改根视图
        app.window.rootViewController = app.mmDrawer;
//        [self presentViewController:[[HomeViewController alloc] init] animated:YES completion:^{
//        }];
        
    }];
}
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView{
    if (aScrollView == _scrollView) {
        CGPoint point = _scrollView.contentOffset;
        point.y = point.y*4;
        _smallScrollView.contentOffset = CGPointMake(_scrollView.contentOffset.x/2, _scrollView.contentOffset.y);
    }


    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
